using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for ActionsControl.
	/// </summary>
	public class ActionsControl : AdminUserControl
	{
    private ExtendedDataGrid actionsGrid;
    private FreeFlowAdministrator.UIActionsControl uiActionsControl;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ActionsControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

      UIActionList actionList = new UIActionList();
      actionList.Add("Refresh", "Refresh the list", new ActionExecuteDelegate(RefreshList));
      actionList.Add("Copy to clipboard", "Copy the list to the clipboard", new ActionExecuteDelegate(CopyToClipboard));
      uiActionsControl.Actions = actionList;
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.actionsGrid = new FreeFlowAdministrator.ExtendedDataGrid();
      this.uiActionsControl = new FreeFlowAdministrator.UIActionsControl();
      ((System.ComponentModel.ISupportInitialize)(this.actionsGrid)).BeginInit();
      this.SuspendLayout();
      // 
      // actionsGrid
      // 
      this.actionsGrid.AllowNavigation = false;
      this.actionsGrid.CaptionVisible = false;
      this.actionsGrid.DataMember = "";
      this.actionsGrid.Dock = System.Windows.Forms.DockStyle.Fill;
      this.actionsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
      this.actionsGrid.Location = new System.Drawing.Point(0, 0);
      this.actionsGrid.Name = "actionsGrid";
      this.actionsGrid.Size = new System.Drawing.Size(394, 328);
      this.actionsGrid.TabIndex = 0;
      // 
      // uiActionsControl
      // 
      this.uiActionsControl.Actions = null;
      this.uiActionsControl.Dock = System.Windows.Forms.DockStyle.Right;
      this.uiActionsControl.Location = new System.Drawing.Point(394, 0);
      this.uiActionsControl.Name = "uiActionsControl";
      this.uiActionsControl.Size = new System.Drawing.Size(150, 328);
      this.uiActionsControl.TabIndex = 1;
      // 
      // ActionsControl
      // 
      this.Controls.Add(this.actionsGrid);
      this.Controls.Add(this.uiActionsControl);
      this.Name = "ActionsControl";
      this.Size = new System.Drawing.Size(544, 328);
      ((System.ComponentModel.ISupportInitialize)(this.actionsGrid)).EndInit();
      this.ResumeLayout(false);

    }
		#endregion

    private ActionCollection actions;
    public void LoadActions(ActionCollection actions)
    {
      this.actions = actions;
      actionsGrid.DataSource = actions;
      actionsGrid.ClearColumns();
      actionsGrid.AddColumn("Name", "Action name");
      actionsGrid.AddColumn("ActionType", "Action type");
      actionsGrid.AddColumn("ToStage", "To stage");
      actionsGrid.AddColumn("Priority");
      actionsGrid.AddColumn("AlertMessage", "Alert message");
      actionsGrid.AddColumn("WhenStarted", "When action started");
      actionsGrid.AddColumn("WhenCompleted", "When action completed");
      actionsGrid.AddColumn("RaiseFlag", "Raises flag");
      actionsGrid.AddColumn("TriggeredByFlag", "Triggered by flag");
      actionsGrid.AddColumn("AvailableTo", "Available to");
      actionsGrid.AddColumn("ChainedAction", "Chained action");
      actionsGrid.AddColumn("UserActionType", "User action type");
      actionsGrid.AddColumn("Form");
      actionsGrid.AddColumn("LoopbackOption", "Loopback option");
      actionsGrid.AddColumn("CloneFolder", "Clone folder");
      actionsGrid.AddColumn("AfterTime", "After time");
      actionsGrid.AddColumn("ReopenFolder", "Re-open folder?");

      // TODO - group and description for creation actions
      actionsGrid.AutosizeColumns();
    }

    private string RefreshList()
    {
      actions.Refresh();
      LoadActions(actions);
      OnRefreshRequired();
      return null;
    }

    private string CopyToClipboard()
    {
      actionsGrid.CopyToClipboard();
      return null;
    }
	}
}
